<?php

header("content-type: text/html; charset=iso-8859-1;", true);

$dbHost = "127.0.0.1:3306";
$dbUser = "root";
$dbPass = "babilonia";
$dbData = "reservas";

$conn = mysql_connect($dbHost,$dbUser,$dbPass) or die(mysql_error());
mysql_select_db($dbData,$conn) or die(mysql_error());

mysql_query("SET NAMES 'utf8';");

if (!isset($_SESSION)) {
  session_start();
}

$start = isset($_GET["start"]) ? (int)$_GET["start"]:0;
$limit = isset($_GET["limit"]) ? (int)$_GET["limit"]:15;

$dia = $_GET['DiaReserva'];

if($conn){

	$select="SELECT * FROM tab_reserva_salas WHERE Sala='212' AND DiaReserva='$dia' AND Cancelada=0 ORDER BY DiaReserva DESC LIMIT $start,$limit";
	$sql_select=mysql_query($select) or die (mysql_error());
	$total_registros = mysql_num_rows($sql_select);

	if($total_registros) {

		$arrJson = array();
	
		while($row= mysql_fetch_object($sql_select)) {
         	$arrJson[] = array(
				'Titulo' => $row->Titulo,
				'DiaReserva' => $row->DiaReserva,
				'HoraInicio' => $row->HoraInicio,
				'HoraFim' => $row->HoraFim
	        );
     	}
	}
}

echo json_encode(array("rows" => $arrJson,"total" => $total_registros));

?>